//
// Created by 高联锐 on 2021/2/18.
//
#include <stdio.h>
#include <string.h>

int main() {
    printf("%s", "chapter06.c run...\n");

    /**
     * while循环
     */
    long int sum, num;
    sum = 0L;
    printf("please enter a long number\n");
    while (scanf("%ld", &num) == 1) {
        sum += num;
        printf("sum = %ld\n", sum);
        printf("please enter a long number\n");
        printf("please enter q to quit\n");
    }

    // 什么是真 C语言中非0为真
    _Bool input_is_good = 10;
    printf("%d\n", input_is_good); // 转换为1


    /**
     * for循环
     */

    for (int i = 0; i < 10; ++i) {
        printf("for循环元素： %d\n", i);
    }

    /**
     * do while
     */
    int count = 10;
    do {
        printf("current count is : %d\n", count);
        count--;
    } while (count > 0);


    for (int i = 0; i < 5; ++i) {
        for (int j = 0; j <= i; ++j) {
            printf("*");
        }
        printf("\n");
    }

    puts("");

    for (int i = 5; i > 0; --i) {
        for (int j = i; j > 0; --j) {
            printf("*");
        }
        printf("\n");
    }

    puts("");

    // 0 1 2 3 4
    // 1 3 5 7 9

    for (int k = 6, j = 1; k > 1; --k,j++) {
        while (j%2 == 0 ){
            j++;
        }
        for (int l = k; l > 0; --l) {
            printf(" ");
        }
        for (int i = j; i > 0; --i) {
            printf("*");
        }
        printf("\n");
    }


    return 0;
};

